using AvalonAdmin.BaseViewModel;
using AvalonAdmin.ViewModels;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using System.Threading.Tasks;
using Ursa.Controls;

namespace AvalonAdmin.Views;

public partial class Login : SplashWindow
{
    public Login()
    {
        InitializeComponent();
    }
    protected override void OnLoaded(RoutedEventArgs e)
    {
        base.OnLoaded(e);

        var _topLevel = TopLevel.GetTopLevel(this);
        if (_topLevel is null)
            return;

        var vm = DataContext as Base;
        if (vm != null)
        {
            if (!WindowNotificationManager.TryGetNotificationManager(_topLevel, out var manager))
            {
                manager = new WindowNotificationManager(_topLevel);
            }
            vm.NotificationManager = manager;
        }
    }

    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    protected override async Task<Window?> CreateNextWindow()
    {
        if (this.DialogResult is true)
        {
            return new MainWindow()
            {
                WindowState = WindowState.Maximized,
                DataContext = new MainViewModel()
            };
        }
        return null;
    }
}